# '''
# import requests
# url='https://passport.cnblogs.com/user/signin'
# headers={
# #'VerificationToken': '2g9jGj41YrjqCj0btUbkVIqX1Xv-IXfFhEpR6GGqCb1EL2tIaZ62uGMY4ESEKXi8A6oY6wGStc6fpJJlN2xS0a9t0zs1:UfoJYNOnvyHg_LUkUd3Kv9SlTPWdcW26ZNw6lE7tSKoZk1dhw2GRZ4lMZ3_bv6uscB-Z3ov99lpwlG3pHZYw6HPyr0w1',
#
# 'Cookie': '_ga=GA1.2.1578020020.1503646785; __gads=ID=34436db75c5e6e7f:T=1504609418:S=ALNI_MazZPifpnH-JkgkGCraPke9g7dB2g; SERVERID=227b087667da6f8e99a1165002db93f6|1505994500|1505991607; _gid=GA1.2.2121858709.1505975140; ASP.NET_SessionId=2x1kka0xwxumk35spmhos4qw',
# #'Referer': 'https://passport.cnblogs.com/user/signin?ReturnUrl=https%3A%2F%2Fwww.cnblogs.com%2F',
# 'X-Requested-With': 'XMLHttpRequest'
#
# }
#
# jsonpassword={'input1':'qbQjjQPwbEchvTx7ZT42CGfIOQSQvsU2ls5YQrh7x7I0BjU4PKAnffNEbhmKcgG3KuiP/n3w6B3CllyQwmjxOvQiDRDrav6onksFCp8VVcEQXUqdXGNZpdhXcRVTrMRmLAsElEqmNuFvQsAD+qLbUTt0cMVekwnaZXfL2eTxlZ0=',
#               'input2':'QxJFg5kiYMCDOI6W3QfjPkn+idpmG/Rc61oQNHgE60duDUS+fXM8z96B07gPFSzWzKiE1gwnVSZw6twiQ3yw0L10au26LD+bxCOdUcbWyM7m9/CPcvqCeMuepXEfFI1+rKwlWjNP8YRGpTIQ2jYfevcAn8y455yk0aERBCK2EQY=',
#             'remember':'True'
#
#     }
# response=requests.post(url=url,headers=headers,json=jsonpassword,verify=False)
# print(response.json())
# print(response.status_code)
# '''
# '''
# import requests,re
# url='http://localhost:8080/jenkins/j_acegi_security_check'
# headers={
# 'Connection': 'keep-alive','Content-Length': '337','Cache-Control': 'max-age=0','Origin': 'http://localhost:8080','Upgrade-Insecure-Requests': '1','Content-Type':'application/x-www-form-urlencoded','User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36',
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8','Referer': 'http://localhost:8080/jenkins/login?from=%2Fjenkins%2F','Accept-Encoding': 'gzip, deflate, br','Accept-Language': 'zh-CN,zh;q=0.8',
# 'Cookie': 'JSESSIONID=561C8E86725FE65B2204616DA2457EA8; screenResolution=1920x1080; hudson_auto_refresh=true'
# }
# input={    "j_username":'admin',    'j_password':'123456',    'from':'',    'Jenkins-Crumb':'09156ccc5b30bb63fc1c13f2d9315e04',    'json':'{"j_username": "admin", "j_password": "123456", "remember_me": false, "from": "/jenkins/", "Jenkins-Crumb": "09156ccc5b30bb63fc1c13f2d9315e04"}',   'Submit':u'登录',}
# response=requests.session().post(url,headers=headers,data=input,verify=False)
# print(response.status_code)
# print(response.text)
# a=re.findall(r'<b>(.+?)</b>',response.text)
# print(a)
# '''
import  requests
# r=requests.Session() #实例
# a=r.get('http://httpbin.org/cookies/set/sessioncookie/123456789')
# print(a.text)
# r1= r.get("http://httpbin.org/cookies")
# print(r1.text)
#
# requests.get('http://httpbin.org/cookies/set/sessioncookie/123456789')
# response=requests.get("http://httpbin.org/cookies")
# print(response.text)

s=requests.session()

r=s.get('http://httpbin.org/cookies')
print(r.text)
s.cookies.update({'hehe': 'cao'})
r1=s.get('http://httpbin.org/cookies',cookies={'lao':'er'})
print(r1.text)
r2=s.get('http://httpbin.org/headers', headers={'x-test2': 'true'})
print(r2.text)
s.headers.update({'x-test3': 'true'}) #添加并更新保持的会话内容
r3=s.get('http://httpbin.org/headers', headers={'x-test4': 'true'})
print(r3.text)
r4=s.get('http://httpbin.org/headers')
print(r4.text)
#因为全部是使用的第一个s，所以r3,不是在r2上面添加的test3


url='https://passport.cnblogs.com/user/signin'
headers={
'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'X-Requested-With':'XMLHttpRequest',
'Referer':'https://passport.cnblogs.com/user/signin',
'Cookie':'_ga=GA1.2.1578020020.1503646785; __gads=ID=34436db75c5e6e7f:T=1504609418:S=ALNI_MazZPifpnH-JkgkGCraPke9g7dB2g; _gid=GA1.2.1146964282.1506304486; SERVERID=227b087667da6f8e99a1165002db93f6|1506318697|1506318696',
}

input={"input1":"FEPyUZnXDX8SmxKYW4W/ThoDjMKA3/cnIolDj6oTBzZrGvDEhYPN5reBSHqjulrBfVvZuVQlbxcnsntYuxf7jwF3PCGY5rfHVyAGfheAh03ngiiXkkHtsLnQzQFZyD0oI016B7TIcok0FQ98+QoHLG2djaxAS772w2BpO0oxPjk=","input2":"YBpPfYiPhebH+bZoaJy/EYmTB9SeGTn7srhlQoFf0EhyWlC/Nf1NqBhF+amsyYqRpff408wvMFvEOVFurSEeZmFEUlAwnxgWAWY7J6dF1k/ugijvvcj2nkAN9Cg8iPRBB2/1hoppVnjo0gxKhpYdW/fE1WgPKWwQG1WeKYBrVB8=","remember":False}
s=requests.session()
response=s.post(url,headers=headers,json=input,verify=False)
print(response.text)

url01='https://i.cnblogs.com/EditPosts.aspx?opt=1'
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3','Accept-Encoding': 'gzip, deflate, br','Content-Type':'application/x-www-form-urlencoded','Content-Length': '9196','Referer':'https://i.cnblogs.com/EditPosts.aspx?opt=1','Cookie':'_ga=GA1.2.1578020020.1503646785; __gads=ID=34436db75c5e6e7f:T=1504609418:S=ALNI_MazZPifpnH-JkgkGCraPke9g7dB2g; _gid=GA1.2.1146964282.1506304486; .CNBlogsCookie=602B3E930B68C346451714EB5F1EB8EA96696DD49FA85DDFB563EC586A8AF5FEA33CC11131D1EC62E86B88A4869661EAD31A4B9B3A21708950B94F4B8F197763094E8F6FB0AE71239EEC841B83EADBD24F3E4099854616190E7FE6834493574AD131F3DC; .Cnblogs.AspNetCore.Cookies=CfDJ8BMYgQprmCpNu7uffp6PrYYPA6VTHOMpw_cSpI8vWMz6Q_OvkKXbtbslBIi67jlY58sOAqcPvhmm376fBRF8fHUcg61NIHZo5lGq3euT2Gvv-TZKTbYZ0Ffxz8ZPYJptMRoxG0B4hEsG87EgG1K9p8BE_oCtGRP2_bF0-TytKg1zUV2l3_QaHFvt8vLOyCth4i7nAXCp9VVtsnERmPuGtr2bW603wy19qPQM0k18yhnSMOcZR5QQ9Mi2yYfGxpzeJW0Ff--8BU28P1zBsFtRFhNRsTMa1-AYlvyxySy9_l19; _gat=1; SERVERID=5600344ccf6bd2d4bb4775a2baf862da|1506319838|1506319802','Connection': 'keep-alive','Upgrade-Insecure-Requests':'1'}
data={'__VIEWSTATE':'',    '__VIEWSTATEGENERATOR':'FE27D343',
      'Editor$Edit$txbTitle':'这个是我们在网页操作时（fiddler抓包）输入的标题',
      'Editor$Edit$EditorBody':'<p>这个是网页操作时输入的内容</p>',
      'Editor$Edit$Advanced$ckbPublished':'on',    'Editor$Edit$Advanced$chkDisplayHomePage':'on',   'Editor$Edit$Advanced$chkComments':'on',    'Editor$Edit$Advanced$chkMainSyndication':'on',   'Editor$Edit$lkbDraft':u'存为草稿',}
response01=s.post(url01,headers=headers,data=data,verify=False)
print(response01.text)

import  requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
url='https://i.cnblogs.com/EditPosts.aspx?opt=1'
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'

}
response=requests.get(url,headers=headers,verify=False,
                    allow_redirects=False
                      )
print(response.status_code)
print(response.headers)
print(response.headers['location'])

import  requests
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': '9307',
'Referer': 'https://i.cnblogs.com/EditPosts.aspx?opt=1',
'Cookie': '_ga=GA1.2.1578020020.1503646785; __gads=ID=34436db75c5e6e7f:T=1504609418:S=ALNI_MazZPifpnH-JkgkGCraPke9g7dB2g; _gid=GA1.2.1146964282.1506304486; SERVERID=be3c89ac356150692df880e95d4e2e5a|1506333694|1506333347; .CNBlogsCookie=2D3763FD410DF249149E80DC618B482F52CA9BDC56A7A8C21AA64300BA8EA3759B5D17319C09D096125DF45A50DF39498D16C7575BC2861B6DEEF3FFE4AA32750340B9ED99625EB6B239A41C588F2EB2A285F649EDB292EB9EE5373214A4E90A0F6F7A2C; .Cnblogs.AspNetCore.Cookies=CfDJ8BMYgQprmCpNu7uffp6PrYYtR9rTqNz1WzJFls5KDVUZTYR2OWgn_ISTr5ClXvNkyX2rybxk7enOU7JP0cJ0OTOcPXXYqXkFPRwYpaQiS2n5rrv_5r_pHuCQSzGcSfo5dn-gdKjmL5HNYdadgBJUUs1nhgJ5qFn2FqkrgwLwfKvcyRx2XacwyOH2AcQtDMiRP5l2eZoK7Ibgi33hZ38cSD0PIL1nVeqU_6v77MQRk_LQSntF9DEJEx_ZE2q8xyNZzKz9LaOsqKmazWKzIbl5Binfm5LWuwQZST19hfQMZ_Nt',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
}
a={'.CNBlogsCookie2D3763FD410DF249149E80DC618B482F52CA9BDC56A7A8C21AA64300BA8EA3759B5D17319C09D096125DF45A50DF39498D16C7575BC2861B6DEEF3FFE4AA32750340B9ED99625EB6B239A41C588F2EB2A285F649EDB292EB9EE5373214A4E90A0F6F7A2C':''}
b={'.Cnblogs.AspNetCore.Cookies':'CfDJ8BMYgQprmCpNu7uffp6PrYYtR9rTqNz1WzJFls5KDVUZTYR2OWgn_ISTr5ClXvNkyX2rybxk7enOU7JP0cJ0OTOcPXXYqXkFPRwYpaQiS2n5rrv_5r_pHuCQSzGcSfo5dn-gdKjmL5HNYdadgBJUUs1nhgJ5qFn2FqkrgwLwfKvcyRx2XacwyOH2AcQtDMiRP5l2eZoK7Ibgi33hZ38cSD0PIL1nVeqU_6v77MQRk_LQSntF9DEJEx_ZE2q8xyNZzKz9LaOsqKmazWKzIbl5Binfm5LWuwQZST19hfQMZ_Nt'
}
coo=requests.cookies.RequestsCookieJar()  #将建一个空的cokies列表
coo.set('.CNBlogsCookie','2D3763FD410DF249149E80DC618B482F52CA9BDC56A7A8C21AA64300BA8EA3759B5D17319C09D096125DF45A50DF39498D16C7575BC2861B6DEEF3FFE4AA32750340B9ED99625EB6B239A41C588F2EB2A285F649EDB292EB9EE5373214A4E90A0F6F7A2C')            #添加账号cookie到列表
coo.set('.Cnblogs.AspNetCore.Cookies','CfDJ8BMYgQprmCpNu7uffp6PrYYtR9rTqNz1WzJFls5KDVUZTYR2OWgn_ISTr5ClXvNkyX2rybxk7enOU7JP0cJ0OTOcPXXYqXkFPRwYpaQiS2n5rrv_5r_pHuCQSzGcSfo5dn-gdKjmL5HNYdadgBJUUs1nhgJ5qFn2FqkrgwLwfKvcyRx2XacwyOH2AcQtDMiRP5l2eZoK7Ibgi33hZ38cSD0PIL1nVeqU_6v77MQRk_LQSntF9DEJEx_ZE2q8xyNZzKz9LaOsqKmazWKzIbl5Binfm5LWuwQZST19hfQMZ_Nt')    #添加密码cookie到列表
s=requests.session()
s.cookies.update(coo) #将列表cookies利用session保持会话,将cookies添加到session
print(s.cookies)
data={'__VIEWSTATE':'',    '__VIEWSTATEGENERATOR':'FE27D343',
      'Editor$Edit$txbTitle':'老规矩01',
      'Editor$Edit$EditorBody':'<p>见证奇迹的时刻</p>',
      'Editor$Edit$Advanced$ckbPublished':'on',    'Editor$Edit$Advanced$chkDisplayHomePage':'on',   'Editor$Edit$Advanced$chkComments':'on',    'Editor$Edit$Advanced$chkMainSyndication':'on',   'Editor$Edit$lkbDraft':'存为草稿',}
response03=s.post(url,headers=headers,data=data,verify=False)
print(response03.cookies)
'''
'''
import  requests,re
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
#用户登陆
url='https://passport.cnblogs.com/user/signin'  #地址
headers={
#'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0',
#'Accept':'application/json, text/javascript, */*; q=0.01',
'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
#'Accept-Encoding':'gzip, deflate, br',
#'Content-Type':'application/json; charset=utf-8',
#'VerificationToken': 'AH-H7g4h9kbpmnMbTci33ATqA2J3LSSo0iFbdagHf9kBIuAYNNk_g9Ma_iaUkwVB_-W0cArmqCghK_ow--85zPGA2pk1:yNdGrYOyCz0jv263Or82IEo0LNlP0SLUMV9EoBLP9UDpc9huXhojT-U4MMCNzE_WajNPqHWbMHoBFDjCczI4K1O1hO41',
'Referer':'https://passport.cnblogs.com/user/signin?ReturnUrl=http://i.cnblogs.com/',


'X-Requested-With':'XMLHttpRequest',
'Cookie':'_ga=GA1.2.1578020020.1503646785; __gads=ID=34436db75c5e6e7f:T=1504609418:S=ALNI_MazZPifpnH-JkgkGCraPke9g7dB2g; SERVERID=dcc5cb8c464da84cc9928c22dd5884f8|1506409953|1506409925',

} #请求报文，也就是raw里面的那个body部分
json={"input1":"ZZrW//aFGrmCMAy6uPcvpIB3NrHss2nif7GtPoH9wznwsLltKkwtd4VxGaPo615rgQKZoAsmT2VAL2gSzbxRV02K9g992wXU5Nlvm6bzNXHySAqQsU4k34MO72042tnZWRSZxkjiKYMWv4rFJYKmMhssiXifZCyIB6aN3jVrWGk=","input2":"Nv3TVydqDU6msE7AvuMqySxmlKJeo5GjtoUnuJSEQ6HKI7ZJuxovN0rbPdf50hXJP4DEDNcdnA2SxlFVfeCwNrAPAPQeQKoopsUtXhu9KC9mGsvg2ca8UKgOf9lXmb4Y2FmNH8yYFizm6A/YkC3QjRerpZSFsCuh9w1Ul3rLjjs=","remember":True}
s=requests.session()  #利用requests.session保持会话
response=s.post(url,headers=headers,json=json,verify=False)
print(response.text)
#准备实现自动发帖
url01='https://i.cnblogs.com/EditPosts.aspx?opt=1'
headers01={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': '9231',
'Referer': 'https://i.cnblogs.com/EditPosts.aspx?opt=1',
'Cookie': '_ga=GA1.2.1578020020.1503646785; __gads=ID=34436db75c5e6e7f:T=1504609418:S=ALNI_MazZPifpnH-JkgkGCraPke9g7dB2g; SERVERID=be3c89ac356150692df880e95d4e2e5a|1506410564|1506409925; .CNBlogsCookie=C96C879C212485FDD5718081EE24950E40667F7E4CC8286E97C364C7A872712ADC7FFA9705BF13174879B5EF02E6AF00FC250907D512F7CFE40B9F3AA1B39C2FA88686205B2B1FDA2F7C22FCC82D8E1D26AB0D5836B8D47278575AD483B63DEB4CD449C9; .Cnblogs.AspNetCore.Cookies=CfDJ8BMYgQprmCpNu7uffp6PrYYYhaaRpGkO3xhIkQQkIBsVzmBjWoDVz5091BHRbN4mXA6ogeqStb0tXOHNyMIa1McQvYasWV6PsBAD4EOI_7hDfDsY-PkYTdkweGmDgWtEThB7owpzIngQvtrcAXca1hoECvQcCuAHvuV7vrZOkDf6YvMqqkpAwy__fq9KPnm5UNDxUIRO8ZvXZQAUmwWY56Kj_WE4q95hB99VAOoDOnJu2owuvthOgBRlptOgJwZ_SeN1xTH1n1UCagp6FW5mSCiGnBaXxZ_YFM3ATqO_oMVi',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
}

data={'__VIEWSTATE':'',    '__VIEWSTATEGENERATOR':'FE27D343',
      'Editor$Edit$txbTitle':'老规矩099',
        #'Editor$Edit$txbTitle':变量,
      'Editor$Edit$EditorBody':'<p>见证奇迹的时刻</p>',
    #'Editor$Edit$EditorBody':'变量',  这个变量的<p></p>'标签不能掉
      'Editor$Edit$Advanced$ckbPublished':'on',    'Editor$Edit$Advanced$chkDisplayHomePage':'on',   'Editor$Edit$Advanced$chkComments':'on',    'Editor$Edit$Advanced$chkMainSyndication':'on',   'Editor$Edit$lkbDraft':'存为草稿',}
response01=s.post(url01,headers=headers01,data=data,verify=False)
#这个算是特有案例，没次添加一个草稿都是有一个id的，
# 比如我们删除商品的时候，他也有一个商品ID，具体看开发那边，讲道理应该有
#所以我们就利用这个ID做文章，类似自动发帖，用户登陆状态不变，cookie不变，然后更换id删除商品或者草稿
postidurl=response01.url   #获取添加草稿后的url
postId=re.findall(r'postid=(.+?)&',postidurl) #正则匹配postid

url03='https://i.cnblogs.com/post/delete'
headers03={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'https://i.cnblogs.com/posts?postConfig=IsDraft',
'Content-Length': '18',
'Cookie': '_ga=GA1.2.1578020020.1503646785; __gads=ID=34436db75c5e6e7f:T=1504609418:S=ALNI_MazZPifpnH-JkgkGCraPke9g7dB2g; SERVERID=be3c89ac356150692df880e95d4e2e5a|1506411031|1506409925; .CNBlogsCookie=C96C879C212485FDD5718081EE24950E40667F7E4CC8286E97C364C7A872712ADC7FFA9705BF13174879B5EF02E6AF00FC250907D512F7CFE40B9F3AA1B39C2FA88686205B2B1FDA2F7C22FCC82D8E1D26AB0D5836B8D47278575AD483B63DEB4CD449C9; .Cnblogs.AspNetCore.Cookies=CfDJ8BMYgQprmCpNu7uffp6PrYYYhaaRpGkO3xhIkQQkIBsVzmBjWoDVz5091BHRbN4mXA6ogeqStb0tXOHNyMIa1McQvYasWV6PsBAD4EOI_7hDfDsY-PkYTdkweGmDgWtEThB7owpzIngQvtrcAXca1hoECvQcCuAHvuV7vrZOkDf6YvMqqkpAwy__fq9KPnm5UNDxUIRO8ZvXZQAUmwWY56Kj_WE4q95hB99VAOoDOnJu2owuvthOgBRlptOgJwZ_SeN1xTH1n1UCagp6FW5mSCiGnBaXxZ_YFM3ATqO_oMVi',
'Connection': 'keep-alive',
}
json={"postId":postId}  #这里的postId可是是个变量，可以从数据库到处一些id之后进行遍历或者不存在的！
response03=s.post(url03,headers=headers03,json=json,verify=False)


